#ifndef MQTTDEVICEREG_H
#define MQTTDEVICEREG_H

#include <QObject>
#include <QMqttClient>
#include <QThread>
#include <QJsonObject>
class MqttDeviceReg : public QObject
{
    Q_OBJECT
public:
    enum class Topic{
        Device_register,
        Device_register_reply
    };
    Q_ENUM(Topic)
    
public:
    explicit MqttDeviceReg(QMap<QString,QString>,QObject *parent = nullptr);
    ~MqttDeviceReg();
    void mqttMonitor();
    bool publishTheme(Topic,QJsonObject);
private:
    void initTopicMap();
    QString getTopic(Topic);
    bool isMqttdisconnServer();
private:
    QString m_client;
    QString m_username;
    QString m_password;
    
    QString m_productKey;
    QString m_productSecret;
    QString m_deviceName;
    QString m_hostname;
    quint16 m_port;
    
    bool m_activeDisconn = false;
    bool m_isfstConnSig = true;
    
    QMap<MqttDeviceReg::Topic,QString> m_topicMap;
    
    QMqttClient* m_mqttClient = nullptr;
private slots:
    void onMessgeReceived(const QMqttMessage &msg);
    void onConnected();
    void onMqttState(QMqttClient::ClientState state);
signals:
    void register_reply(QJsonObject);
    void sigConnService();
};

#endif // MQTTDEVICEREG_H
/*
  mqtt接口封装类
 */
